package com.jiajia.study.Service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.Date;

/**
 * @Title: MessageService
 * @Author zjj
 * @Package com.jiajia.study.Service
 * @Date 2024/3/7 10:02
 * @description: 消息 service 组件
 */

@Service
@Slf4j
public class MessageService {

    @Resource
    private AmqpTemplate amqpTemplate;

    public void sendMessage(String message){
        Message msg = new Message(message.getBytes(StandardCharsets.UTF_8));
        amqpTemplate.convertAndSend("direct.exchange.a","error",msg);
        log.info("==============send message success : {}",new Date());
    }
}
